/*
 * @lc app=leetcode.cn id=713 lang=cpp
 * @lcpr version=30204
 *
 * [713] 乘积小于 K 的子数组
 */

// @lcpr-template-start
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lcpr-template-end
// @lc code=start
class Solution
{
public:
    int numSubarrayProductLessThanK(vector<int> &nums, int k)
    {
        if (k <= 1)
            return 0;
        int n = nums.size();

        int count = 0;
        int curMulti = 1;
        int left = 0;
        for (int right = 0; right < n; ++right)
        {
            curMulti *= nums[right];
            while (curMulti >= k)
            {
                curMulti /= nums[left++];
            }
            count += right - left + 1;  //统计以right为结尾的子数组
        }
        return count;
    }
};
// @lc code=end

/*
// @lcpr case=start
// [10,5,2,6]\n100\n
// @lcpr case=end

// @lcpr case=start
// [1,2,3]\n0\n
// @lcpr case=end

 */
